package com.example.mymatch.service.Imp;

import com.example.mymatch.dao.IPost;
import com.example.mymatch.model.Post;
import com.example.mymatch.service.IPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对服务接口规范的方法实现
 * 编写者：吴茂景
 */
@Service
public class IPostServiceImpl implements IPostService {

    @Autowired
    private IPost postMapper;   //对后端数据操作某张表的定义规范 编写者：吴茂景

    @Override//添加方法
    public int insertPost(Post post){
        int postValue=0;
        //查看当前部门名称不能重复
        Post post1=new Post();
        post1.setPostName(post.getPostName());
        List<Post> getC=postMapper.getAllPost(post1);
        if (getC.size()>=1){
            //不可以添加部门名称
            postValue=-1;
        }else {
            postValue=postMapper.insertPost(post);
        }
        return postValue;
    }

    @Override
    public List<Post> getAllPost(Post post){
        return postMapper.getAllPost(post);
    }

    @Override
    public int updatePost(Post post){
        int postValue=0;
        //判断主键不能为0
        if (post.getId()!=0){
            //主键信息必修存在

            //名称不能重复

            postValue=postMapper.updatePost(post);
        }
        return postValue;
    }

    @Override
    public  int deletePost(Post post){
        int postValue=0;
        //判断主键不能为0
        if (post.getId()!=0){
            //主键是否有其他表有关联，如果关联，则先删除其他表的信息，或者给出此条信息不允许被删除


            postValue=postMapper.deletePost(post);
        }
        return postValue;
    }

    //单条查询
    @Override
    public Post getPost(Post post){
        Post post1=new Post();
        if (post.getId()!=0){
            post1=postMapper.getPost(post);
        }
        return post1;
    }
}
